package ah.h2;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Test {
	public static void main(String[] a) throws Exception {
		Class.forName("org.h2.Driver");
		Connection conn = DriverManager.getConnection(
				"jdbc:h2:/media/F/workspace/test/WebRoot/res/data", "root", "root");
		// add application code here
		Statement stmt = conn.createStatement();
		stmt.execute("DROP TABLE IF EXISTS TEST");
		stmt.execute("CREATE TABLE TEST(ID INT PRIMARY KEY,NAME VARCHAR(255))");
		stmt.execute("INSERT INTO TEST VALUES(1, 'Hello')");
		stmt.execute("INSERT INTO TEST VALUES(2, 'World')");
		
		ResultSet rs = stmt.executeQuery("SELECT * FROM TEST ORDER BY ID");
		while (rs.next()) {
			System.out.println(rs.getInt("ID") + "," + rs.getString("NAME"));
		}
		
		stmt.execute("UPDATE TEST SET NAME='Hi' WHERE ID=1");
		stmt.execute("DELETE FROM TEST WHERE ID=2");
		stmt.execute("DROP TABLE IF EXISTS TEST");
		
		conn.close();
	}
}
